package com.mazaiting.course.domain;

import com.mazaiting.course.exception.ExceptionEnum;

/***
 * 响应
 * @author mazaiting
 * @datetime 2022/3/7
 */
public class Response {
    /**成功是否标记*/
    private int ret;
    /**消息*/
    private String message;
    /**数据*/
    private Object data;

    public Response() {
    }
    public Response(ExceptionEnum exceptionEnum) {
        this.ret = exceptionEnum.getStatus();
        this.message=exceptionEnum.getMessage();
    }

    public Response(int ret, String message) {
        this.ret = ret;
        this.message = message;
    }

    public Response(int ret, String message, Object data) {
        this.ret = ret;
        this.message = message;
        this.data = data;
    }

    /**
     * 服务器错误返回结果集
     * @return
     */
    public static Response error() {
        Response resp = new Response();
        resp.setRet(ExceptionEnum.ERROR.getStatus());
        resp.setMessage(ExceptionEnum.ERROR.getMessage());
        return resp;
    }
    /**
     * 返回特定的消息
     * @param message
     * @return
     */
    public Response message(String message){
        this.setMessage(message);
        return this;
    }

    /**
     * 返回特定的结果码
     * @param ret
     * @return
     */
    public Response code(Integer ret){
        this.setRet(ret);
        return this;
    }

    /**
     * 服务器成功返回结果
     * @return
     */
    public static Response Success() {
        Response resp = new Response();
        resp.setRet(ExceptionEnum.SUCCESS.getStatus());
        resp.setMessage(ExceptionEnum.SUCCESS.getMessage());
        return resp;
    }

    /**
     * 设置自定义结果集
     * @param exceptionEnum
     * @return
     */
    public static Response setResult(ExceptionEnum exceptionEnum){
        Response resp = new Response();
        resp.setRet(exceptionEnum.getStatus());
        resp.setMessage(exceptionEnum.getMessage());
        return resp;
    }




    public int getRet() {
        return ret;
    }

    public Response setRet(int ret) {
        this.ret = ret;
        return this;
    }

    public String getMessage() {
        return message;
    }

    public Response setMessage(String message) {
        this.message = message;
        return this;
    }

    public Object getData() {
        return data;
    }

    public Response setData(Object data) {
        this.data = data;
        return this;
    }
}
